{% extends 'layout.twig' %}

{% block header %}
    {% include('header.twig') %}
{% endblock %}

{% block extra_scripts %}
    <script type="text/javascript" src="{{ constant('PATH_JS') }}dialogs.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var LABEL_0218 = '{{ constant('Strings::LABEL_0218') }}';
            var LABEL_0030 = '{{ constant('Strings::LABEL_0030') }}';
            var LABEL_0031 = '{{ constant('Strings::LABEL_0031') }}';
            var LABEL_0039 = '{{ constant('Strings::LABEL_0039') }}';

            var url_base = '{{ constant('BASE_WWW') }}';

            var tab_selected = parseInt('{{ tab_selected ?: 0 }}');
            var accordion_selected = parseInt('{{ accordion_selected ?: 0 }}');

            $('#tabs').tabs({
                selected: tab_selected,
                select: function (event, ui) {
                    var url = $.data(ui.tab, 'load.tabs');
                    switch (url) {
                        case url_base + 'accounts/list':
                            break;
                        case url_base + 'nodes/list':
                            break;
                        case url_base + 'profiles/list':
                            break;
                        case url_base + 'courses/list':
                            location.href = url;
                            return false;
                        case url_base + 'users/index':
                            break;
                    }
                },
                load: function (event, ui) {
                    $('button').button();
                    $('ul#icons li').hover(
                            function () {
                                $(this).addClass('ui-state-hover');
                            },
                            function () {
                                $(this).removeClass('ui-state-hover');
                            }
                    );
                    switch ($.data(ui.tab, 'load.tabs')) {
                        case url_base + 'accounts/list':
                            set_dialogCreateAccount(LABEL_0218, LABEL_0030);
                            set_dialogReadAccount(LABEL_0031);
                            set_dialogUpdateAccount(LABEL_0218, LABEL_0030);
                            set_dialogDeleteAccount(LABEL_0218, LABEL_0030);
                            break;
                        case url_base + 'nodes/list':
                            set_dialogCreateNode(LABEL_0218, LABEL_0030);
                            set_dialogUpdateNode(LABEL_0218, LABEL_0039, LABEL_0030);
                            set_dialogDeleteNode(LABEL_0218, LABEL_0030);
                            $('.node').hover(
                                    function () {
                                        $(this).addClass('node-hover');
                                    },
                                    function () {
                                        $(this).removeClass('node-hover');
                                    }
                            );
                            break;
                        case url_base + 'profiles/list':
                            set_dialogDeleteProfile(LABEL_0218, LABEL_0030);
                            window.profile = {
                                create: function () {
                                    var form = $('#profiles form[name=profil_creation]').get(0);
                                    if (check_dialogProfile(form['new_designation']))
                                        form.submit();
                                },
                                update: function (num) {
                                    var form = $('#profiles form[name=profil_update_' + num + ']').get(0);
                                    if (check_dialogProfile(form['designation'])) {
                                        form.action = url_base + 'profiles/update?profile=list';
                                        form.submit();
                                    }
                                },
                                delete: function (num) {
                                    var form = $('#profiles form[name=profil_update_' + num + ']').get(0);
                                    form.action = url_base + 'profiles/delete?profile=list';
                                    $('#dialog_delete_profile').data({form: form}).dialog('open');
                                }
                            };
                            break;
                        case url_base + 'courses/list':
                            break;
                        case url_base + 'users/index':
                            set_dialogDeleteUser(LABEL_0218, LABEL_0030);
                            $('#accordion_user').accordion({header: 'h3', active: accordion_selected, autoHeight: false, navigation: true});
                            $('#datepicker_user_date_start_contract_creation').datepicker({dateFormat: 'dd/mm/yy'});
                            $('#datepicker_user_date_end_contract_creation').datepicker({dateFormat: 'dd/mm/yy'});
                            $('#datepicker_user_date_start_contract_update').datepicker({dateFormat: 'dd/mm/yy'});
                            $('#datepicker_user_date_end_contract_update').datepicker({dateFormat: 'dd/mm/yy'});
                            break;
                    }
                }
            });

            $('#content').show();
        });
    </script>
{% endblock %}

{% block content %}
    <div id="content" class="td_blue_round" style="margin-left:40px;margin-right:40px;display:none;">
        <font class="titre_1">{{ constant('Strings::LABEL_0015') }}</font>
        <div id="tabs"> 
            <ul>
                {% for tab in tabs %}
                    <li>
                        <a href="{{ tab.name }}">{{ tab.text }}</a>
                    </li>
                {% endfor %}
            </ul>
        </div>
    </div> 
{% endblock %}